package com.atguigu.team.view;

import com.atguigu.team.domain.Employee;
import com.atguigu.team.domain.Programmer;
import com.atguigu.team.service.NameListService;
import com.atguigu.team.service.TeamException;
import com.atguigu.team.service.TeamService;

import java.util.List;
import java.util.Scanner;
public class TeamView {
    private NameListService ListSvc=new NameListService();
    private TeamService TeamSvc=new TeamService();
    public void enterMainMenu(){
        Scanner scan=new Scanner(System.in);
        boolean loopFlag=true;
        int input=0;
        while(loopFlag) {
            if(input!=1) {
                listAllEmployees();
            }
            System.out.print("1-团队列表 2-添加团队成员 3-删除团队成员 4-退出 请选择(1-4):" );
            input=scan.nextInt();
            switch (input) {
                case 1:
                    getTeam();
                    break;
                case 2:
                    addMember();
                    break;
                case 3:
                    delMember();
                    break;
                case 4:
                    System.out.print("是否退出?(Y/N):");
                    if(scan.next().equalsIgnoreCase("Y")){
                        loopFlag=false;
                }
                    break;
                default:
                    System.out.println("输入错误，请重新输入");
                    break;
            }
        }
    }
    private void listAllEmployees(){
        System.out.println("-----------------------------------------------开发团队调度软件-------------------------------------\n");
        Employee[] employees=ListSvc.getAllEmployees();
        System.out.println("ID\t姓名\t年龄\t工资\t职位\t状态\t奖金\t股票\t领用设备");
        for(int i=0;i<employees.length;i++){
            System.out.println(employees[i]);
        }
        System.out.println("------------------------------------------------------------------------------------------------\n");
    }
    private void getTeam(){
        System.out.println("-----------------成员团队列表------------------------\n");
        Programmer[] team=TeamSvc.getTeam();
        if(team==null||team.length==0){
            System.out.println("开发团队没有成员");
        }else{
            System.out.println("TID/ID\t姓名\t年龄\t工资\t职位\t奖金\t股票\n");
            for(int i=0;i< team.length;i++){
                System.out.println(team[i].getDetailsForTeam());
            }
        }
    }
    private void addMember(){
        Scanner scan=new Scanner(System.in);
        System.out.println("-------------------------添加团队成员-------------------------");
        System.out.println("请输入要添加员工的id");
        int id=scan.nextInt();
        try {
            Employee employee = ListSvc.getEmployee(id);
            TeamSvc.addMember((Programmer)employee);
            System.out.println("添加成功");
        }catch(TeamException e){
            System.out.println("添加失败，原因:"+e.getMessage());
        }
    }
    private void delMember(){
        Scanner scanner=new Scanner(System.in);
        System.out.println("----------------------删除团队成员------------------------------");
        System.out.println("请输入要删除员工的Id");
        int input=scanner.nextInt();
        System.out.println("确认是否删除(Y/N):");
        if(scanner.next().equalsIgnoreCase("N")){
            return;
        }else{
            try{
                TeamSvc.removeMember(input);
                System.out.println("删除成功");
            }catch (TeamException e){
                System.out.println("删除失败,原因"+e.getMessage());
            }
        }
    }
    public static void main(String[] args){
        TeamView view=new TeamView();
        view.enterMainMenu();

    }
}
